from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import QDialog, QLabel, QGridLayout
from configs.strings import translate


class AboutDialog(QDialog):
    def __init__(self, lang):
        super().__init__()
        self.setWindowTitle(translate['ABOUT'][lang])
        self.resize(400, 300)
        authorLabel = QLabel(make_font("Created by Tearsyu<syx1026@qq.com>"))
        authorLabel.setAlignment(QtCore.Qt.AlignHCenter)
        dateLabel = QLabel(make_font("Last Build Date: 2021/07/07"))
        dateLabel.setAlignment(QtCore.Qt.AlignHCenter)
        otherLabel = QLabel(make_font('This is a rebar detector app by python3.8.'))
        otherLabel.setAlignment(QtCore.Qt.AlignHCenter)
        self.buttons = QtWidgets.QDialogButtonBox(
            QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)

        layout = QGridLayout()
        layout.addWidget(authorLabel, 0, 0)
        layout.addWidget(dateLabel, 1, 0)
        layout.addWidget(otherLabel, 2, 0)
        layout.addWidget(self.buttons, 3, 0)
        self.setLayout(layout)
        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)


def make_font(msg=''):
    """
    To set font of text show in text
    :param msg: message to show
    :return: matched font
    """
    return '<font size={} color="{}" face="{}"> {} </font>'.format(4, "black", "verdana", msg)
